<script>
import i18n from '@/locale'

export default {
  name: 'DynInput',
  directives: {
    blur: {
      inserted: function(el) {
        el.blur()
      }
    }
  },
  model: {
    prop: 'value',
    event: 'input'
  },
  props: {
    value: {
      type: [String, Number], // 验证类型后续可以增加
      default: ''
    },
    item: {
      type: Object,
      default: () => ({})
    }
  },
  methods: {
    handlerInput(value) {
      this.$emit('input', value.trim())
      this.item.event && this.item.event(value)
    },
    handlerEnter(e) {
      this.item.handlerEnter && this.item.handlerEnter(e)
    }
  },
  render: function(h) {
    return (
      <el-input
        value={this.value}
        on-input={this.handlerInput.bind(this)}
        on-focus={this.handlerEnter.bind(this)}
        disabled={this.item.disabled}
        readonly={this.item.readonly}
        style={this.item.style}
        placeholder={`${i18n.t('pleaseInput')}${this.item.label}`}
        show-word-limit={this.item.show_word_limit || false}
        maxlength={this.item.maxlength || undefined}
        clearable>
      </el-input>
    )
  }
}
</script>

